/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * NuGat-API named Chameleon developed by Simon De Baets to Verimag.
 *
 */
package chameleon.model.NuGatStructure.utils;

import chameleon.gameSolver.NuGat.NuGatInterface;
import chameleon.model.NuGatStructure.NuGatStructure;
import com.sun.jna.Pointer;

/**
 * This class is a wrapper to the C struct node
 * 
 * @author simon
 */
public class Node extends NuGatStructure {
    
    public Node (Pointer node, NuGatInterface nugat){
        super (node,nugat);
    }
    
    /**
     * 
     * @param type
     * @param node_ptr_left
     * @param node_ptr_right
     * @param nugat 
     */
    
    public Node(int type, Pointer node_ptr_left, Pointer node_ptr_right, 
            NuGatInterface nugat){
        super(nugat.new_node(type, node_ptr_left, node_ptr_right),nugat);
    }
    
    public Node (int type, Node left, Node right, NuGatInterface nugat){
        super (nugat.new_node(type, left.ptr(), right.ptr()),nugat);
    }
    
    /**
     * 
     * @param node_ptr_x
     * @param node_ptr_y
     * @return node_ptr
     */
    
    public Node cons(Node x, Node y){
        return new Node (nugat_.cons(x.ptr(), y.ptr()),nugat_);
    }
    
    public Node cons(Node y){
        return new Node (nugat_.cons(this.ptr(), y.ptr()),nugat_);
    }
    
    /**
     * Return the right part of the node
     * @return Node 
     */
    
    public Node cdr(){
        return new Node (nugat_.cdr(this.ptr()),nugat_);
    }
    
    /**
     * Return the left part of the node
     * @return Node 
     */
    
    public Node car(){
        return new Node (nugat_.car(this.ptr()),nugat_);
    }
   
    /**
     * Returns a new sequence containing the same elements as X but
     * in reverse order
     * @return 
     */
    
    public Node reverse(){
        return new Node (nugat_.reverse(this.ptr()),nugat_);
    }
    
    public void freeNode(){
        nugat_.free_node(this.ptr());
    }
    
    /**
     * 
     * @param type
     * @param node_ptr_left
     * @param node_ptr_right
     * @return 
     */
    
    public Node findNode(int type, Pointer node_ptr_left, Pointer node_ptr_right){
        return new Node(nugat_.find_node(type, node_ptr_left, node_ptr_right),nugat_);
    }
    
    public String sprintNode (){
        return nugat_.sprint_node(this.ptr());
    }
    
    
    public int printNode (String file){
        return nugat_.print_node(nugat_.CmdOpenFile(file), this.ptr());
    }
    
    public int printSexp (String file){
        return nugat_.print_sexp(nugat_.CmdOpenFile(file), this.ptr());
    }
    
    
    /**
     * return the size of the node
     * @return 
     */
    
    public int llength(){
        return (nugat_.llength(this.ptr()));
    }

    public int getType(){
        return nugat_.Chameleon_node_get_type(this.ptr());
    }
}
